package com.lianniu.web.tea.supply.contoller;

import java.math.BigDecimal;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.tea.supply.model.TeaSupplyProduct;
import com.lianniu.web.tea.supply.model.TeaSupplyProductPic;
import com.lianniu.web.tea.supply.service.ITeaSupplyService;
import com.lianniu.web.tea.user.collect.model.TeaCollect;

@Controller
@RequestMapping("/rest/tea/supply")
public class TeaSupplyController {

	private final static Logger logger = Logger.getLogger(TeaSupplyController.class);
	
	@Autowired
	private ITeaSupplyService tesSupplyService;
	
	@RequestMapping(value = "/supply1", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody BaseResult supply1(HttpServletRequest req) {
		logger.info("TeaSupplyController  supply1 begin.");
		try {
			logger.info("supply1 begin.");
			
			String supplyId = req.getParameter("supplyId");
			String lat = req.getParameter("lat");
			String lon = req.getParameter("lon");
			String title = req.getParameter("title");
			String name = req.getParameter("name");
			String legalName = req.getParameter("legalName");
			String legalIdCard = req.getParameter("legalIdCard");
			String teaPhone = req.getParameter("teaPhone");
			String teaPrice = req.getParameter("teaPrice");
			String teaProject = req.getParameter("teaProject");
			String teaNotice = req.getParameter("teaNotice");
			String userId = req.getParameter("userId");
			String yyzzPic = req.getParameter("yyzzPic");
			String sfzmPic = req.getParameter("sfzmPic");
			String sffmPic = req.getParameter("sffmPic");
			String coverPic = req.getParameter("coverPic");
			String cshjPic = req.getParameter("cshjPic");
			String hdnrPic = req.getParameter("hdnrPic");
			
			TeaSupplyProduct product = new TeaSupplyProduct();
			
			TeaSupplyProductPic productPic = new TeaSupplyProductPic();
			
			productPic.setYyzzPic(yyzzPic);
			productPic.setSfzmPic(sfzmPic);
			productPic.setSffmPic(sffmPic);
			productPic.setCoverPic(coverPic);
			productPic.setCshjPic(cshjPic);
			productPic.setHdnrPic(hdnrPic);
			productPic.setAdduser(userId);
			
			product.setTeaTitle(title);
			product.setProductname(name);
			product.setLegalName(legalName);
			product.setLegalIdcard(legalIdCard);
			product.setTeaPhone(teaPhone);
			product.setTeaPrice(new BigDecimal(teaPrice));
			product.setTeaProject(teaProject);
			product.setTeaNotice(teaNotice);
			product.setAdduser(userId);
			if(supplyId==null){
				product.setProductid(null);
			}else{
				product.setProductid(Long.valueOf(supplyId));
			}
			product.setTeaProLat(lat);
			product.setTeaProLon(lon);
			
			BaseResult baseResult = tesSupplyService.saveSupply1(productPic,product);
			logger.info("supply1 end.");
			logger.info("TeaSupplyController supply1 end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaSupplyController supply1 error:" + e.getMessage());
			logger.error("TeaSupplyController supply1 end.");
			return BaseResult.exception(e.getMessage());
		}
	}
	
	@RequestMapping(value = "/supply3", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody BaseResult supply3(HttpServletRequest req) {
		logger.info("TeaSupplyController  supply3 begin.");
		try {
			logger.info("supply3 begin.");
			
			String supplyId = req.getParameter("supplyId");
			String lat = req.getParameter("lat");
			String lon = req.getParameter("lon");
			String title = req.getParameter("title");
			String legalName = req.getParameter("legalName");
			String teaPhone = req.getParameter("teaPhone");
			String teaArea = req.getParameter("teaArea");
			String teaHight = req.getParameter("teaHight");
			String coverArea = req.getParameter("coverArea");
			String detailAddress = req.getParameter("detailAddress");
			String limitTime = req.getParameter("limitTime");
			String teaPrice = req.getParameter("teaPrice");
			String treeNum = req.getParameter("treeNum");
			String teaNotice = req.getParameter("teaNotice");
			String gandenType = req.getParameter("gandenType");
			String teaType = req.getParameter("teaType");
			String userId = req.getParameter("userId");
			String yyzzPic = req.getParameter("yyzzPic");
			String sfzmPic = req.getParameter("sfzmPic");
			String sffmPic = req.getParameter("sffmPic");
			String coverPic = req.getParameter("coverPic");
			String jtPic = req.getParameter("jtPic");
			String syPic = req.getParameter("syPic");
			String cslmPic = req.getParameter("cslmPic");
			
			TeaSupplyProduct product = new TeaSupplyProduct();
			
			TeaSupplyProductPic productPic = new TeaSupplyProductPic();
			
			productPic.setYyzzPic(yyzzPic);
			productPic.setSfzmPic(sfzmPic);
			productPic.setSffmPic(sffmPic);
			productPic.setCoverPic(coverPic);
			productPic.setJtPic(jtPic);
			productPic.setSyPic(syPic);
			productPic.setCslmPic(cslmPic);
			productPic.setAdduser(userId);
			
			product.setTeaTitle(title);
			product.setLegalName(legalName);
			product.setTeaPhone(teaPhone);
			product.setTeaArea(new BigDecimal(teaArea));
			product.setTeaHight(new BigDecimal(teaHight));
			product.setCoverArea(new BigDecimal(coverArea));
			product.setDetailAddress(detailAddress);
			product.setLimitTime(limitTime);
			product.setTeaPrice(new BigDecimal(teaPrice));
			product.setTreeNum(Long.valueOf(treeNum));
			product.setTeaNotice(teaNotice);
			product.setGandenType(gandenType);
			product.setTeaType(teaType);
			product.setAdduser(userId);
			if(supplyId==null){
				product.setProductid(null);
			}else{
				product.setProductid(Long.valueOf(supplyId));
			}
			product.setTeaProLat(lat);
			product.setTeaProLon(lon);
			
			BaseResult baseResult = tesSupplyService.saveSupply3(productPic,product);
			logger.info("supply3 end.");
			logger.info("TeaSupplyController supply3 end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaSupplyController supply3 error:" + e.getMessage());
			logger.error("TeaSupplyController supply3 end.");
			return BaseResult.exception(e.getMessage());
		}
	}
	
	@RequestMapping(value = "/supply4", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody BaseResult supply4(HttpServletRequest req) {
		logger.info("TeaSupplyController  supply4 begin.");
		try {
			logger.info("supply4 begin.");
			String supplyId = req.getParameter("supplyId");
			String lat = req.getParameter("lat");
			String lon = req.getParameter("lon");
			String title = req.getParameter("title");
			String name = req.getParameter("name");
			String teaAge = req.getParameter("teaAge");
			String teaYear = req.getParameter("teaYear");
			String legalIdCard = req.getParameter("legalIdCard");
			String detailAddress = req.getParameter("detailAddress");
			String teaPhone = req.getParameter("teaPhone");
			String teaPrice = req.getParameter("teaPrice");
			String teaMonthPrice = req.getParameter("teaMonthPrice");
			String teaNotice = req.getParameter("teaNotice");
			String userId = req.getParameter("userId");
			String sex = req.getParameter("sex");
			String teaTrip = req.getParameter("teaTrip");
			String teaIndustry = req.getParameter("teaIndustry");
			String sfzmPic = req.getParameter("sfzmPic");
			String sffmPic = req.getParameter("sffmPic");
			String zgzsPic = req.getParameter("zgzsPic");
			String coverPic = req.getParameter("coverPic");
			String zgcyPic = req.getParameter("zgcyPic");
			
			TeaSupplyProduct product = new TeaSupplyProduct();
			
			TeaSupplyProductPic productPic = new TeaSupplyProductPic();
			
			productPic.setSfzmPic(sfzmPic);
			productPic.setSffmPic(sffmPic);
			productPic.setZgzsPic(zgzsPic);
			productPic.setCoverPic(coverPic);
			productPic.setZgcyPic(zgcyPic);
			productPic.setAdduser(userId);
			
			product.setTeaTitle(title);
			product.setProductname(name);
			product.setTeaAge(teaAge);
			product.setTeaYear(teaYear);
			product.setLegalIdcard(legalIdCard);
			product.setDetailAddress(detailAddress);
			product.setTeaPhone(teaPhone);
			product.setTeaPrice(new BigDecimal(teaPrice));
			product.setTeaNotice(teaNotice);
			product.setTeaSex(sex);
			product.setTeaTrip(teaTrip);
			product.setTeaIndustry(teaIndustry);
			product.setAdduser(userId);
			if(supplyId==null){
				product.setProductid(null);
			}else{
				product.setProductid(Long.valueOf(supplyId));
			}
			product.setTeaProLat(lat);
			product.setTeaProLon(lon);
			
			BaseResult baseResult = tesSupplyService.saveSupply4(productPic,product);
				
			logger.info("supply4 end.");
			logger.info("TeaSupplyController supply4 end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaSupplyController supply4 error:" + e.getMessage());
			logger.error("TeaSupplyController supply4 end.");
			return BaseResult.exception(e.getMessage());
		}
	}

	
	@RequestMapping(value = "/releaseInf", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody BaseResult releaseInf(HttpServletRequest req) {
		logger.info("TeaSupplyController  releaseInf begin.");
		try {
			logger.info("releaseInf begin.");
			String supplyId = req.getParameter("supplyId");
			String lat = req.getParameter("lat");
			String lon = req.getParameter("lon");
			String title = req.getParameter("title");
			String text = req.getParameter("text");
			String userId = req.getParameter("userId");
			String teaInfoClass = req.getParameter("teaInfoClass");
			
			String coverPic = req.getParameter("coverPic");
			
			TeaSupplyProduct product = new TeaSupplyProduct();
			
			TeaSupplyProductPic productPic = new TeaSupplyProductPic();
			
			productPic.setCoverPic(coverPic);
			productPic.setAdduser(userId);
			product.setTeaTitle(title);
			product.setDesception(text);
			product.setAdduser(userId);
			product.setTeaInfoClass(teaInfoClass);
			if(supplyId==null){
				product.setProductid(null);
			}else{
				product.setProductid(Long.valueOf(supplyId));
			}
			product.setTeaProLat(lat);
			product.setTeaProLon(lon);
			
			BaseResult baseResult = tesSupplyService.releaseInf(productPic,product);
				
			logger.info("releaseInf end.");
			logger.info("TeaSupplyController releaseInf end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaSupplyController releaseInf error:" + e.getMessage());
			logger.error("TeaSupplyController releaseInf end.");
			return BaseResult.exception(e.getMessage());
		}
	}
	
	
	@RequestMapping(value = "/demand1", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody BaseResult demand1(HttpServletRequest req) {
		logger.info("TeaSupplyController  demand1 begin.");
		try {
			logger.info("demand1 begin.");
			
			String supplyId = req.getParameter("supplyId");
			String lat = req.getParameter("lat");
			String lon = req.getParameter("lon");
			
			String name = req.getParameter("name");
			String teaPhone = req.getParameter("teaPhone");
			String detailAddress = req.getParameter("detailAddress");
			String teaArea = req.getParameter("teaArea");
			String teaHight = req.getParameter("teaHight");
			String coverArea = req.getParameter("coverArea");
			String teaLocation = req.getParameter("teaLocation");
			String teaPrice = req.getParameter("teaPrice");
			String desception = req.getParameter("desception");
			String teaNotice = req.getParameter("teaNotice");
			String gandenType = req.getParameter("gandenType");
			String teaType = req.getParameter("teaType");
			String userId = req.getParameter("userId");

			
			TeaSupplyProduct product = new TeaSupplyProduct();

			
			product.setProductname(name);
			product.setTeaPhone(teaPhone);
			product.setDetailAddress(detailAddress);
			product.setTeaArea(new BigDecimal(teaArea));
			product.setTeaHight(new BigDecimal(teaHight));
			product.setCoverArea(new BigDecimal(coverArea));
			product.setTeaLocation(teaLocation);
			product.setTeaPrice(new BigDecimal(teaPrice));
			product.setDesception(desception);
			product.setTeaNotice(teaNotice);
			product.setGandenType(gandenType);
			product.setTeaType(teaType);
			product.setAdduser(userId);
			if(supplyId==null){
				product.setProductid(null);
			}else{
				product.setProductid(Long.valueOf(supplyId));
			}
			product.setTeaProLat(lat);
			product.setTeaProLon(lon);
			
			BaseResult baseResult = tesSupplyService.saveDemand1(product);
			logger.info("demand1 end.");
			logger.info("TeaSupplyController demand1 end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaSupplyController demand1 error:" + e.getMessage());
			logger.error("TeaSupplyController demand1 end.");
			return BaseResult.exception(e.getMessage());
		}
	}
	
	@RequestMapping(value = "/demand2", method = { RequestMethod.POST, RequestMethod.GET })
	public @ResponseBody BaseResult demand2(HttpServletRequest req) {
		logger.info("TeaSupplyController  demand2 begin.");
		try {
			logger.info("demand2 begin.");
			
			String supplyId = req.getParameter("supplyId");
			String lat = req.getParameter("lat");
			String lon = req.getParameter("lon");

			String name = req.getParameter("name");
			String teaPhone = req.getParameter("teaPhone");
			String legalIdCard = req.getParameter("legalIdCard");
			String detailAddress = req.getParameter("detailAddress");
			String teaAge = req.getParameter("teaAge");
			String teaLocation = req.getParameter("teaLocation");
			String teaPrice = req.getParameter("teaPrice");
			String teaNotice = req.getParameter("teaNotice");
			String teaSex = req.getParameter("teaSex");
			String teaTrip = req.getParameter("teaTrip");
			String teaIndustry = req.getParameter("teaIndustry");
			String userId = req.getParameter("userId");
			
			TeaSupplyProduct product = new TeaSupplyProduct();

			
			product.setProductname(name);
			product.setTeaPhone(teaPhone);
			product.setLegalIdcard(legalIdCard);
			product.setDetailAddress(detailAddress);
			product.setTeaAge(teaAge);
			product.setTeaLocation(teaLocation);
			product.setTeaPrice(new BigDecimal(teaPrice));
			product.setTeaNotice(teaNotice);
			product.setTeaSex(teaSex);
			product.setTeaTrip(teaTrip);
			product.setTeaIndustry(teaIndustry);
			
			
			product.setAdduser(userId);
			if(supplyId==null){
				product.setProductid(null);
			}else{
				product.setProductid(Long.valueOf(supplyId));
			}
			product.setTeaProLat(lat);
			product.setTeaProLon(lon);
			
			BaseResult baseResult = tesSupplyService.saveDemand2(product);
			logger.info("demand2 end.");
			logger.info("TeaSupplyController demand2 end.");
			return baseResult;
		} catch (Exception e) {
			logger.error("TeaSupplyController demand2 error:" + e.getMessage());
			logger.error("TeaSupplyController demand2 end.");
			return BaseResult.exception(e.getMessage());
		}
	}
}
